package solution._0040._0045;

import common.Utils;

/**
 * Created by chen_snow
 * Date: 2021/5/31 22:28
 * Description: 跳跃游戏 II
 */
public class Solution {
    public static void main(String[] args) {
        jump(new int[]{2, 3, 1, 1, 4});
    }

    public static int jump(int[] nums) {
        int[] dp = new int[nums.length];
        for (int i = 0; i < dp.length; i++) {
            dp[i] = Integer.MAX_VALUE;
        }

        dp[0] = 0;

        Utils.print(dp);

        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j <= i + nums[i] && j < nums.length; j++) {
                dp[j] = Math.min(dp[i] + 1, dp[j]);
            }
        }

        Utils.print(dp);
        return dp[nums.length - 1];
    }
}
